//Program by:
//Ben Schmidt - bjs778 - 11054018
//Mike Nimeck - mfn028 - 11053045
//Jeff Huang - jlh105 - 11050226
//
//Fully implemented by hand, but OpenGL SuperBible example
//used heavily as reference

// Flocking render vertex shader
#version 330

// Model-view-projection matrix
uniform mat4 mvp;
uniform int base_size;
uniform float depth_divisor;

// Instanced attributes (position and velocity of the flock member)
layout (location = 0) in vec3 instance_position;

// Output color from the vertex shader
flat out vec4 vs_color;

void main(void)
{
    vec4 pos = vec4(instance_position, 1.0);
    
    gl_PointSize = base_size - (instance_position.z / depth_divisor);
    
    // Calculate a color based in gl_InstanceID - give them rainbow colors!
    
    int color = int(mod(gl_InstanceID, 7));
    
    if (color == 0){
	//red!
	vs_color = vec4(1.0f, 0.2f, 0.2f, 1.0f);
    }
    else if (color == 1){
	//orange!
	vs_color = vec4(1.0f, 0.7f, 0.2f, 1.0f);
    }
    else if (color == 2){
	//yellow!
	vs_color = vec4(1.0f, 1.0f, 0.2f, 1.0f);
    }
    else if (color == 3){
	//green!
	vs_color = vec4(0.2f, 1.0f, 0.2f, 1.0f);
    }
    else if (color == 4){
	//blue!
	vs_color = vec4(0.2f, 0.2f, 1.0f, 1.0f);
    }
    else if (color == 5){
	//indigo!
	vs_color = vec4(0.5f, 0.2f, 0.7f, 1.0f);
    }
    else {
	//violet!
	vs_color = vec4(0.7f, 0.2f, 1.0f, 1.0f);
    }
    
    // Output position
    gl_Position = mvp * pos;
}
